package cn.holy.app.xcddt.database;

import androidx.room.TypeConverter;
import android.text.TextUtils;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

import cn.holy.app.xcddt.utils.HDateUtils;

/**
 * Created by 69568 on 2018/2/24.
 */

public class Converters {

    @TypeConverter
    public static Date fromTimestamp(String value) {


        return value == null ? null : HDateUtils.strToDateLong(value);
    }

    @TypeConverter
    public static String dateToTimestamp(Date date) {
        return date == null ? null : HDateUtils.dateToStrLong(date);
    }

    @TypeConverter
    public static List<String> stringToList(String string) {
        if (string != null) {
            String[] split = TextUtils.split(string, ",");
            return Arrays.asList(split);
        } else {
            return null;
        }
    }

    @TypeConverter
    public static String listToString(List<String> stringList) {
        if (stringList != null) {
            return TextUtils.join(",", stringList);
        } else {
            return null;
        }
    }
}
